{% extends "base.html" %}
{% load humanize %}
{% load bootstrap_pagination %}

{% block content %}
    <div class="page-header"><h1>收藏夹</h1></div>

    <div class="row">
        <div class="col-md-4">
            <div class="row">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">过滤</div>
                        <div class="list-group">
                            <a href="{{ filter_urls.all }}" class="list-group-item{% if curfilter == 'all' %} active{% endif %}">全部</a>
                            <a href="{{ filter_urls.translated }}" class="list-group-item{% if curfilter == 'translated' %} active{% endif %}">已翻译</a>
                            <a href="{{ filter_urls.schedule }}" class="list-group-item{% if curfilter == 'schedule' %} active{% endif %}">待译</a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">排序</div>
                        <div class="list-group">
                            <a href="{{ sort_urls.date }}" class="list-group-item{% if cursort == 'date' %} active{% endif %}">收藏时间</a>
                            <a href="{{ sort_urls.views }}" class="list-group-item{% if cursort == 'views' %} active{% endif %}">浏览量</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-8">
            {% for favorite in favorites %}
                {% if forloop.counter0 %}<hr>{% endif %}
                {% with favorite.article as article %}
                    {% if article.status == article.TRANSLATED %}
                        <h4><a href="{% url 'translations:detail' article.id %}">{{ article.title }}</a></h4>
                        <small><a href="{{ article.recommend_user.profile.get_absolute_url }}">{{ article.recommend_user.profile }}</a> 推荐于 {{ article.recommend_date|naturaltime }}</small>
                        <p>{{ article.section_set.first.best_translation.content|striptags|truncatewords:6 }}</p>
                    {% else %}
                        <h4><a href="{% url 'translations:detail' article.id %}">{{ article.original_title }}</a></h4>
                        <h5>{{ article.title }} (
                            {% with article.translate_rate as translate_rate %}
                                {% if translate_rate > 0 %}
                                    已翻译{{ translate_rate }}%
                                {% else %}
                                    未翻译
                                {% endif %}
                            {% endwith %}
                        )</h5>
                        <small><a href="{{ article.recommend_user.profile.get_absolute_url }}">{{ article.recommend_user.profile }}</a> 推荐于 {{ article.recommend_date|naturaltime }}</small>
                        <p>{{ article.section_set.first.content|striptags|truncatewords:50 }}</p>
                    {% endif %}
                {% endwith %}
            {% endfor %}

            {% if favorites.paginator.num_pages > 1 %}
                <hr>
                {% bootstrap_paginate favorites range=10 %}
            {% endif %}
        </div>
    </div>
{% endblock %}